<?php
if (!defined('ROOT')) {
   die("Impossible de voir ce fichier directement.");
}
include_once (ROOT.'/inc/classes/Model.php');

class User extends Model
{
    var $table="users";
    var $index = "id";
    
    var $id;
    var $lastname;
    var $firstname;
    var $birthdate;
    var $password;
    var $gender;
    var $hash;
    var $login;
    var $email;
    var $address;
    var $zipcode;
    var $city;
    var $country;
    var $phone;
    var $activated = false;
    var $privilege = "user";
    var $created;
    var $updated;
    
    
    function getFields()
    {
        $this->fields['id'] = $this->id;
        $this->fields['gender'] = $this->gender;
        $this->fields['lastname'] = $this->lastname;
        $this->fields['firstname'] = $this->firstname;
        $this->fields['birthdate'] = $this->birthdate;
        $this->fields['password'] = $this->password;
        $this->fields['hash'] = $this->hash;
        $this->fields['login'] = $this->login;
        $this->fields['email'] = $this->email;
        $this->fields['address'] = $this->address;
        $this->fields['zipcode'] = $this->zipcode;
        $this->fields['city'] = $this->city;
        $this->fields['country'] = $this->country;
        $this->fields['phone'] = $this->phone;
        $this->fields['activated'] = $this->activated;
        $this->fields['privilege'] = $this->privilege;
        $this->fields['created'] = $this->created;
        $this->fields['updated'] = $this->updated;
    }
    
    function setFields()
    {
       $this->id = $this->fields['id'];
       $this->gender = $this->fields['gender'];
        $this->lastname = $this->fields['lastname'];
        $this->firstname = $this->fields['firstname'];
        $this->birthdate = $this->fields['birthdate'];
        $this->password = $this->fields['password'];
        $this->hash = $this->fields['hash'];
        $this->login = $this->fields['login'];
        $this->email = $this->fields['email'];
        $this->address = $this->fields['address'];
        $this->zipcode = $this->fields['zipcode'];
        $this->city = $this->fields['city'];
        $this->country = $this->fields['country'];
        $this->phone = $this->fields['phone'];
        $this->activated = $this->fields['activated'];
        $this->privilege = $this->fields['privilege'];
        $this->created = $this->fields['created'];
        $this->updated = $this->fields['updated'];
    }
    
   function generateHash(){
	$result = "";
	$charPool = '0123456789abcdefghijklmnopqrstuvwxyz';
	for($p = 0; $p<15; $p++)
		$result .= $charPool[mt_rand(0,strlen($charPool)-1)];
	return sha1(md5(sha1($result)));
   }
}
